package com.example.mobile2021606163crw0618;

import android.content.ContentValues;
import android.content.Context;
import android.database.sqlite.SQLiteDatabase;
import android.database.sqlite.SQLiteOpenHelper;

import androidx.annotation.Nullable;

public class MySQLiteOpenHelper extends SQLiteOpenHelper {
    public MySQLiteOpenHelper(@Nullable Context context, @Nullable String name, @Nullable SQLiteDatabase.CursorFactory factory, int version) {
        super(context, name, factory, version);
    }

    @Override
    public void onCreate(SQLiteDatabase db) {
        String sql = "create table users(_id integer primary key autoincrement,name varchar(20) not null,age interger,score float)";
        db.execSQL(sql);
        ContentValues contentValues = new ContentValues();
        contentValues.put("name","小红");
        contentValues.put("age",15);
        contentValues.put("score",200);
        db.insert("users", null, contentValues);
        contentValues.put("name","小李");
        contentValues.put("age",20);
        contentValues.put("score",80);
        db.insert("users", null, contentValues);
    }

    @Override
    public void onUpgrade(SQLiteDatabase db, int oldVersion, int newVersion) {

    }
}
